package com.heima.media.controller;

import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.ChannelDto;
import com.heima.media.entity.WmChannel;
import com.heima.media.service.IWmChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 频道的控制层
 */
@RestController
@RequestMapping("/api/v1/channel")
@Api(tags = "频道管理api")
public class ChannelController {

    @Autowired
    private IWmChannelService iWmChannelService;

    /**
     *  频道根据名称 模糊查询
     * @param channelDto
     * @return
     */
    @PostMapping("/list")
    @ApiOperation(value = "根据名称模糊查询分页列表", notes = "author:mcm")  // value指名称  notes 备注
    public ResponseResult listByName(@RequestBody ChannelDto channelDto ){
          return iWmChannelService.listByName(channelDto);
    }

    /**
     * /api/v1/channel
     * 根据名称保存频道
     */
    @PostMapping("/channel")
    public ResponseResult saveName(@RequestBody WmChannel channel){

        //调用业务层保存
        return iWmChannelService.saveName(channel);

    }

    @GetMapping("/channels")
    public ResponseResult channels(){
        List<WmChannel> list = iWmChannelService.listBystatus();
        return ResponseResult.okResult(list);
    }
}
